package Clothing.controller.lease;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import Clothing.bean.BaseResponse;
import Clothing.bean.request.lease.AddLeaseRequest;
import Clothing.bean.request.lease.EditLeaseByIdRequest;
import Clothing.bean.request.lease.GetAllLeaseRequest;
import Clothing.bean.request.lease.GetLeaseByIdRequest;
import Clothing.bean.respose.lease.GetAllLeaseResponse;
import Clothing.bean.respose.lease.GetLeaseByIdResponse;
import Clothing.service.lease.LeaseService;
import Clothing.util.ResultModel;

@Controller
@RequestMapping(value = "/Lease")
public class LeaseController {

    @Resource
    private LeaseService leaseService;
    
    
    @ResponseBody
    @RequestMapping(value = "/getAllLease",method = RequestMethod.POST)
    public ResultModel getAllLease(@RequestBody GetAllLeaseRequest request){
        ResultModel resultModel = new ResultModel();
        GetAllLeaseResponse response = new GetAllLeaseResponse();
        int result = leaseService.getAllLease(request,response);
        switch (result) {
            case 0:
                response.setSuccess("0");
                break;
            case 1:
                response.setSuccess("1");
                break;
            default:
                break;
        }
        resultModel.setData(response);
        return resultModel;
    }
    
    
    @ResponseBody
    @RequestMapping(value = "/getLeaseById",method = RequestMethod.POST)
    public ResultModel getLeaseById(@RequestBody GetLeaseByIdRequest request){
        ResultModel resultModel = new ResultModel();
        GetLeaseByIdResponse response = new GetLeaseByIdResponse();
        int result = leaseService.getLeaseById(request,response);
        switch (result) {
            case 0:
                response.setSuccess("0");
                break;
            case 1:
                response.setSuccess("1");
                break;
            default:
                break;
        }
        resultModel.setData(response);
        return resultModel;
    }
    
    @ResponseBody
    @RequestMapping(value = "/editLeaseById",method = RequestMethod.POST)
    public ResultModel editLeaseById(@RequestBody EditLeaseByIdRequest request){
        ResultModel resultModel = new ResultModel();
        BaseResponse response = new BaseResponse();
        int result = leaseService.editLeaseById(request);
        switch (result) {
            case 0:
                response.setSuccess("1");
                break;
            case 1:
                response.setSuccess("0");
                break;
            default:
                break;
        }
        resultModel.setData(response);
        return resultModel;
    }
    
    @ResponseBody
    @RequestMapping(value = "/deleteLeaseById",method = RequestMethod.POST)
    public ResultModel deleteLeaseById(@RequestBody GetLeaseByIdRequest request){
        ResultModel resultModel = new ResultModel();
        BaseResponse response = new BaseResponse();
        int result = leaseService.deleteLeaseById(request);
        switch (result) {
            case 0:
                response.setSuccess("1");
                break;
            case 1:
                response.setSuccess("0");
                break;
            default:
                break;
        }
        resultModel.setData(response);
        return resultModel;
    }
    
    @ResponseBody
    @RequestMapping(value = "/addLease" , method = RequestMethod.POST)
    public ResultModel addLease(@RequestBody AddLeaseRequest request){
        ResultModel resultModel = new ResultModel();
        BaseResponse response = new BaseResponse();
        int result = leaseService.addLease(request);
        switch (result) {
            case 0:
                response.setSuccess("1");
                break;
            case 1:
                response.setSuccess("0");
                break;
            default:
                break;
        }
        resultModel.setData(response);
        return resultModel;
    }
}
